package com.usian.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.car.Car;
import com.usian.entity.Result;
import com.usian.entity.ResultCodeEnum;
import com.usian.mapper.CarMapper;
import com.usian.service.CarService;
import com.usian.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:张永杰
 * @ClassName: CarServiceImpl
 * @Date: 2024/12/11
 * @Description:
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements CarService {

    @Value("${oss.qiniu.url}")
    private String url;
    @Value("${oss.qiniu.accessKey}")
    private String accessKey;
    @Value("${oss.qiniu.secretKey}")
    private String secretKey;
    @Value("${oss.qiniu.bucket}")
    private String bucket;

    @Override
    public Result<List<Car>> findAllCar() {
        List<Car> list = list();
        list.stream().forEach(car->{car.setPicture(url+car.getPicture());});
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @Override
    public String uploadCar(byte[] bytes, String newFileName) {
        QiniuUtils.uploadQiniu2(accessKey,secretKey,bucket,bytes,newFileName);
        return url+newFileName;
    }
}
